package com.shoux.api.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class MybatisFillHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"insertTime",Date.class, new Date());
        this.strictInsertFill(metaObject,"updateTime",Date.class, new Date());
//        String userJobNumber = String.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
//        this.strictInsertFill(metaObject,"creator",String.class, userJobNumber);
        this.strictInsertFill(metaObject,"delFlag",Boolean.class, false);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"updateTime",Date.class, new Date());
        this.setFieldValByName("updatedTime", new Date(), metaObject);
//        String userJobNumber = String.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
//        this.strictUpdateFill(metaObject,"editor",String.class, userJobNumber);
    }
}
